package b_;

import org.junit.Test;

import java.io.*;

/*
    自定义类的使用
 */
public class StudentDemo {

    @Test
    public void testWrite() throws IOException {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("stu.obj"));
        Student stu = new Student();
        stu.setId(20);
        stu.setName("张三");
        stu.setAge(18);
        stu.setSex('男');
        oos.writeObject(stu);
    }

    @Test
    public void testRead() throws IOException, ClassNotFoundException {
        //输入流对象
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("stu.obj"));
        Student stu = (Student)ois.readObject();
        System.out.println(stu);
    }

}
